class Post < ActiveRecord::Base
 validates_presence_of :content

 acts_as_ferret :fields => [:title, :content]
 acts_as_taggable
 
 belongs_to :user
 belongs_to :avatar
 belongs_to :community, :counter_cache=>:posts_count
 has_many :comments, :as => :commentable, :dependent => :destroy
 
 auto_html_for :content do
  image
  #youtube :width => 400, :height => 250
  link :target => "_blank", :rel => "nofollow"
  
  # <com value="techno" /> - комьюнити
  # <user value="test_1"/> - пользователь
  # <inside value="название подкаченного">информация которая подкачена</inside>
  prodject_format
 end
 
 named_scope :journal, :conditions=>{:community_id=>nil}
 
 def to_param
   id.to_s + "-" + slug
 end
  
 def before_save
   self.slug = title.parameterize
 end
 
 def title
   return (self[:title].blank? ? "Без названия" : self[:title])
 end
 
 	def user_avatar
		return user.avatar if self.avatar.nil?
		user.avatars.find_by_id(self.avatar_id)
	end
end
